package com.jlc.book.shop.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jlc.book.shop.delegate.BookDelegate;
import com.jlc.book.shop.to.BookTO;
import com.jlc.book.shop.util.BookUtil;

public class PreviousAction {

	public String searchBookInfo(HttpServletRequest request,
			HttpServletResponse response) {
		

		String page="searchBookDef.jsp";
		
		HttpSession session=request.getSession();
		String bnm=session.getAttribute("BOOK_NAME").toString();
		String author=session.getAttribute("AUTHOR").toString();
		String pub=session.getAttribute("PUBLICATION").toString();
		String edi=session.getAttribute("EDITION").toString();
		int start=Integer.parseInt(session.getAttribute("START").toString());
		System.out.println("k"+start);
		String str=session.getAttribute("COST").toString();
		
		float bcost=0.0f;
		if(str.length()>0)
		
			bcost=Float.parseFloat(str);
		
		BookTO bto=new BookTO(bnm, author, pub, edi, bcost);
		int total=BookDelegate.getTotalNumberOfBook(bto);
		int noBook=BookUtil.NUMBER_OF_BOOK;
		
		if(start>0)
		
			start=start-noBook;
		
		else
			
			start=0;
		
		int end=start+noBook;
		
		session.setAttribute("START", new Integer(start));
		session.setAttribute("TOTAL", new Integer(total));
		session.setAttribute("END", new Integer(end));
		
		List bookList=BookDelegate.searchBook(bto, start, noBook);
		session.setAttribute("BOOK_LIST", bookList);
		

		return page;
		
	}

}
